﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 保险费率综合测试
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void btnCaculate_Click(object sender, EventArgs e)
		{
			int age = Convert.ToInt32(txtAge.Text);//BUG 未对不合法格式进行处理;
			int credit = Convert.ToInt32(txtCredit.Text);//BUG 未对不合法格式进行处理;
			double ageCoefficient = 0;
			int discount = 0;
			int result = 0;

			if (age < 16 || age >= 100)
			{
				MessageBox.Show("输入的年龄错误！请确认输入的年龄是否大于等于16岁且小于100岁。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			else if (credit < 0)
			{
				MessageBox.Show("输入的点数错误！请确认输入的点数是否大于0", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			else if (credit >= 12)
			{
				result = 0;
			}
			else
			{
				if (age >= 16 && age < 25)
				{
					ageCoefficient = 2.8;
					if (credit < 1)
					{
						discount = 50;
					}
					else
					{
						discount = 0;
					}
				}
				else if (age >= 25 && age <= 35)//BUG 此处将<35改为了<=35
				{
					ageCoefficient = 1.8;
					if (credit <= 3)//BUG 此处将<3改为了<=3
					{
						discount = 50;
					}
					else
					{
						discount = 0;
					}
				}
				else if (age >= 35 && age < 45)
				{
					ageCoefficient = 1;
					if (credit < 5)
					{
						discount = 100;
					}
					else
					{
						discount = 0;
					}
				}
				else if (age > 45 && age < 60)//BUG 此处将>=45改为了>45
				{
					ageCoefficient = 0.8;
					if (credit < 7)
					{
						discount = 150;
					}
					else
					{
						discount = 0;
					}
				}
				else if (age >= 61 && age < 100)//BUG 此处将>=60改为了>=61
				{
					ageCoefficient = 1.5;
					if (credit < 6)//BUG 此处将<5 改为了<6
					{
						discount = 200;
					}
					else
					{
						discount = 200;//BUG 此处将=0改为了=200
					}
				}
				else
				{
				}
				result = Convert.ToInt32(500 * ageCoefficient - discount);
				MessageBox.Show(string.Format("您的保险费为{0}元", result), "结果", MessageBoxButtons.OK, MessageBoxIcon.Information);

			}
		}
	}
}